<?php
/**
 * Conversations - A lightweight BB for Xaraya
 *
 * @package modules
 * @copyright (C) 2003-2006 The Digital Development Foundation.
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @link http://www.xaraya.com
 *
 * @subpackage conversations
 * @link http://xaraya.com/index.php/release/760.html
 * @author John Cox
*/

/**
 * Get all subscriptions
 * @returns array
 * @return array of zero or more subscriptions, or NULL on failure
 * @param tagid interger tag id 
 */
function conversations_userapi_gettags_byuid($args)
{
    extract($args);

    // Optional arguments
    if (!isset($startnum)) {$startnum = 1;}
    if (!isset($numitems)) {$numitems = -1;}

    $dbconn =& xarDBGetConn();
    $xartable =& xarDBGetTables();
    $ctags  = $xartable['ctags'];
    $csubs  = $xartable['csubs'];
   
    $query = "SELECT $ctags.xar_id, $ctags.xar_tag, $ctags.xar_timestamp, $ctags.xar_lastvisit, "
            . "$ctags.xar_status, $ctags.xar_uid, $ctags.xar_count, $ctags.xar_options "
            . " FROM $ctags "
            . " LEFT JOIN $csubs "
            . " ON $ctags.xar_id = $csubs.xar_tagid "
            . " WHERE $csubs.xar_uid = ? "
            . " ORDER by $ctags.xar_id";

    $where = array();
    $bind = array();
    
    $bind[] = (int)$uid;

    $result =& $dbconn->SelectLimit($query, $numitems, $startnum-1, $bind);
    if (!$result) return;

    $tags = array();
    for (; !$result->EOF; $result->MoveNext()) {
        list($id, $tag, $timestamp, $lastvisit, $status, $uid, $count, $options) = $result->fields;

        $tags[] = array(
                'id'     => $id,
                'tag'       => xarVarPrepForDisplay($tag),
                'timestamp' => $timestamp,
                'lastvisit' => $lastvisit,
                'uid'       => $uid,
                'status'    => $status,
                'count'     => $count//,
                //'options'   => unserialize($options)
        );
    }
    $result->Close();
    return $tags;
}
?>